#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：python_learning 
@File ：slow_down.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2024/6/4 下午3:13 
"""

import functools
import time


def slow_down(_func=None, *, rate=1):
	"""Sleep given amount of seconds before calling the function"""

	def decorator_slow_down(func):
		@functools.wraps(func)
		def wrapper_slow_down(*args, **kwargs):
			time.sleep(rate)
			return func(*args, **kwargs)

		return wrapper_slow_down

	if _func is None:
		return decorator_slow_down
	else:
		return decorator_slow_down(_func)


if __name__ == '__main__':
	@slow_down(rate=2)
	def countdown(from_number):
		if from_number < 1:
			print("Liftoff!")
		else:
			print(from_number)
			countdown(from_number - 1)
